import Vue from 'vue'
import config from '@/config'

var marked = require('marked')

Vue.filter('avatar', e => {
    if (!e) {
        return config.qiniu + 'FhCciTUs9PAHMox4I88y9K6924FI'
    }
    return config.qiniu + e
})

Vue.filter('mdText', md => {
    const mdHtml = marked(md, {
        sanitize: false
    });
    let text = ""
    try {
        text = mdHtml
            .match(/<\S+>(.*)<\S+>/g)
            .map(i => {
                return i.match(/<\S+>(.*)<\S+>/)[1];
            })
            .join("")
    } finally {
        text = text.substring(0, 100)
        if (text.length === 100) {
            text = text + "..."
        }
    }
    return text
})